//server.cpp
#include "header.h"
int main()
{
    // 1.创建命名管道
    umask(0);
    int ret = mkfifo(filename, mode);
    if (ret < 0)
    {
        cout << errno << ":" << strerror(errno) << endl;
        exit(1);
    }
    // 2.打开命名管道文件
    int fd = open(filename, O_RDONLY);
    assert(ret != -1);
    // 3.准备通信
    while (1)
    {
        cout << "server:I have already prepared for receiving the client message" << endl;
        char buf[MAX] = {0};
        int n = read(fd, buf, sizeof(buf) - 1);
        if (n < 0)
        {
            cout << errno << ":" << strerror(errno) << endl;
            break;
        }
        else if (n == 0)
        {
            cout << "读到文件尾" << endl;
            break;
        }
        else
        {
            buf[n]='\0';
            cout<<"server:I have received the  client message"<<endl;
            cout<<buf<<endl;
        }
        sleep(1);
    }
    unlink(filename);//删除命令管道

    return 0;
}